package com.test.pack1.demo.d2;

import org.jetbrains.annotations.NotNull;

import java.util.Iterator;

/**
 * Created by dws on 2017/11/10.
 * 下压堆栈  链表实现
 * 空栈的top 为-1
 */
public class Stack<Item> implements Iterable<Item> {
    //栈顶
    private Node first;
    //元素数量
    private int N;

    private  class Node{
        Item item;
        Node next;
    }
    public boolean isEmpty(){return N==0;}
    public int size(){return  N;}
    public void push(Item item){
        Node oldfrist = first;
        first = new Node();
        first.item = item;
        first.next = oldfrist;
        N++;
    }

    public Item pop(){
        Item item = first.item;
        first = first.next;
        N--;
        return item;
    }
    @NotNull
    @Override
    public Iterator<Item> iterator() {
        return null;
    }
}
